//引入字体图标样式
require("../../assets/fonts/iconfont.css");
const { log } = require("debug/src/browser");
//引入axios
const axios = require("../../assets/js/axios.js");
//引入自定义js
let obj = require("../../assets/js/my.js");
let $ = obj.$;
let local = obj.local;
//引入自己的样式
require("./sports_course_details.less");
window.addEventListener("load", function () {
	//根据id通过axios渲染页面
	// 获取课堂的Id
	let Id = location.search.split("=").pop();
	(async function () {
		// 发送请求获取数据
		let ss = await axios.get(`/api/train/courseDetail?id=${Id}`);
		let data = ss.data.data;
		// console.log(data);
		//数据存储在本地
		local.setItem("fragments", data.fragments);
		// 渲染函数
		function render(data) {
			let keyArr = [
				"name",
				"calorie",
				"time",
				"peoplenum",
				"desc",
				"frequency",
				"instrument",
			];
			// 图片
			$(".poster img").src = axios.defaults.baseURL + data.imgurl;
			for (let k in data) {
				if (keyArr.includes(k)) {
					$(`#${k}`).textContent = data[k];
				}
			}
		}
		render(data);
	})();
	//点击左箭头回退
	$(".poster .icon-zuojiantou").addEventListener("click", function () {
		history.back();
	});
	//开始训练点击
	$("#startBtn").addEventListener("click", function () {
		location.href = "./sports_course_training.html";
	});
});
